import Taro, { Component } from '@tarojs/taro'
import { View, Button, Text, Image } from '@tarojs/components'
import { connect } from '@tarojs/redux'

import { add, minus, asyncAdd } from '../../actions/counter'

import './index.scss'

import '../../assets/style/common.scss'

import menu from '../../assets/images/menu.png'

import list from '../../assets/data/list.json'

import Counter from '../../components/count/counter'


@connect(({ counter }) => ({
  counter
}), (dispatch) => ({
  add() {
    dispatch(add())
  },
  dec() {
    dispatch(minus())
  },
  asyncAdd() {
    dispatch(asyncAdd())
  }
}))
class Index extends Component {

  state = {
    count: 100
  }

  config = {
    navigationBarTitleText: '首页-gp18'
  }

  componentWillReceiveProps(nextProps) {
    console.log(this.props, nextProps)
  }

  componentWillUnmount() { }

  componentDidShow() {

    console.log(list.list)
  }

  componentDidHide() { }

  handleClick = () => {
    Taro.switchTab({
      url: '/pages/log/log?username=admin&userid=1'
    })
  }

  changeCount = (num) => {
    this.setState({
      count: this.state.count + num
    })
  }


  render() {
    return (
      <View className='index'>
        {/* <Button className='add_btn' onClick={this.props.add}>+</Button>
        <Button className='dec_btn' onClick={this.props.dec}>-</Button>
        <Button className='dec_btn' onClick={this.props.asyncAdd}>async</Button> */}
        {/* <Button onClick={this.handleClick}>日志</Button>
        <View className="container"><Text>{this.props.counter.num}</Text></View>
        <View><Text>Hello, World</Text></View>
        <Image src={menu} style={{width:'50px',height:'50px'}}></Image> */}
        <Counter count={this.state.count} changeCount={this.changeCount}></Counter>
      </View>
    )
  }
}

export default Index
